package com.mall.product.server.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ProductThreadPoolConfig {

    @Bean(name = "itemThreadPoolExcuter")
    public ThreadPoolExecutor itemThreadPoolExcuter(ItemThreadPoolProperties itemThreadPoolProperties){

        return new ThreadPoolExecutor(
                //java查吗
                itemThreadPoolProperties.getCorePoolSize(),
                itemThreadPoolProperties.getMaxPoolSize(),   //魔法值
                itemThreadPoolProperties.getKeepAliveTime(),
                TimeUnit.MINUTES,
                new LinkedBlockingDeque<>(itemThreadPoolProperties.getQueueLength()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

//    @Bean
//    public ThreadPoolExecutor imgUploadThreadPoolExcuter(){
//
//        return new ThreadPoolExecutor(
//                //java查吗
//                6,
//                20,
//                5,
//                TimeUnit.MINUTES,
//                new LinkedBlockingDeque<>(300),
//                Executors.defaultThreadFactory(),
//                new ThreadPoolExecutor.AbortPolicy()
//        );
//    }
}
